package com.unity.bh3.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.unity.bh3.entity.UserCharacter;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 用户角色关联Mapper接口
 */
@Mapper
public interface UserCharacterMapper extends BaseMapper<UserCharacter> {
    
    /**
     * 根据用户ID查询用户拥有的角色列表
     * @param userId 用户ID
     * @return 用户角色列表
     */
    @Select("SELECT uc.*, c.name as characterName, c.description as characterDescription, " +
            "c.rarity as characterRarity, c.type as characterType, c.image_path as characterImagePath " +
            "FROM user_character uc LEFT JOIN `character` c ON uc.character_id = c.id " +
            "WHERE uc.user_id = #{userId} ORDER BY c.rarity DESC, uc.obtain_time DESC")
    List<UserCharacter> selectUserCharactersWithDetails(@Param("userId") Long userId);
    
    /**
     * 根据用户ID和角色ID查询用户角色
     * @param userId 用户ID
     * @param characterId 角色ID
     * @return 用户角色
     */
    @Select("SELECT * FROM user_character WHERE user_id = #{userId} AND character_id = #{characterId}")
    UserCharacter selectByUserIdAndCharacterId(@Param("userId") Long userId, @Param("characterId") Long characterId);
    
    /**
     * 根据用户ID查询用户拥有的角色ID列表
     * @param userId 用户ID
     * @return 角色ID列表
     */
    @Select("SELECT character_id FROM user_character WHERE user_id = #{userId}")
    List<Long> selectCharacterIdsByUserId(@Param("userId") Long userId);
}